/*自定义--校区管理-课程管理*/
import { routerRedux } from 'dva/router';
import * as LoginService from '../services/basics';

export default {
  namespace: 'campucoursepage',
  state: {
    data: [],
  },
  effects: {
     //课程包 -admin 
    //查询所有课程包
    *fetch_coursePage({ payload }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/system/getAloneCoursePage',payload); 
    	yield put({type: 'save',payload: response.data.obj});
    },
    //课程包 admin 查询单个
    *fetchId_coursePage({ payload ,callback}, { call, put }) {
      	const response = yield call(LoginService.get,'/api/web/system/getAloneCoursePage',payload);
    	callback(response.data.res,response.data.resMsg,response.data.obj[0]);
    },
    //课程包 admin 新增
    *add_coursePage({ payload ,callback}, { call, put }) {
       const response = yield call(LoginService.post,'/api/web/system/insertAloneCoursePage',payload);
       callback(response.data.res,response.data.resMsg);
       yield put({type:'fetch_coursePage'});
    },
    *add_coursePageCourse({ payload ,callback}, { call, put }) {
      	const response = yield call(LoginService.post,'/api/web/system/insertAloneCourseToPage',payload);
    	 callback(response.data.res,response.data.resMsg);
    	 yield put({type:'fetch_coursePage'});
    },
    //课程包 admin 编辑
    *edit_coursePage({ payload ,callback}, { call, put }) {
      	const response = yield call(LoginService.puts,'/api/web/system/updateAloneCoursePage',payload);
    	callback(response.data.res,response.data.resMsg);
    	yield put({type:'fetch_coursePage'});
    },
    //课程包 admin 禁用和启用
    *disabled_coursePage({ payload ,callback}, { call, put }) {
      const response = yield call(LoginService.puts,'/api/web/system/updateAloneCoursePageState',payload);
    	callback(response.data.res,response.data.resMsg);
    	yield put({type:'fetch_coursePage'});
    },
    //查询父级课程包
    *fetch_coursePageselect({ payload,callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/system/getAloneCoursePage',payload); 
    	callback(response.data.res,response.data.obj);
    },
    //查询课程包下的课程
    *fetch_coursePagese_courselect({ payload,callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/system/getCourseToPage',payload); 
    	callback(response.data.res,response.data.obj);
    },
    //查询未添加进课程包的课程
    *fetch_coursePagese_courselect2({ payload,callback }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/system/getOtherCourseToPage',payload); 
    	callback(response.data.res,response.data.obj);
    },
    //查询学校 select
    *fetch_ListByschoolselect({ payload,callback }, { call, put }) {  
      const response = yield call(LoginService.post,'/api/web/school/getSchoolListByOrg'); 
    	callback(response.data.res,response.data.obj);
    },
    //单独课程 admin 课程包下的课程
    *fetchId_course({ payload ,callback}, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/system/getAloneCourse',payload);
    	callback(response.data.res,response.data.obj);
    },

    //学校课程包
    *insertSchoolCoursePage({ payload ,callback}, { call, put }) {
      const response = yield call(LoginService.post,'/api/web/schoolCoursePage/insertSchoolCoursePage',payload);
    	callback(response.data.res,response.data.obj);
    },
    //主题课默认list
     *fetch_theme({ payload }, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/system/getAloneCoursePageC',payload); 
    	yield put({type: 'save',payload: response.data.obj});
    },
		//主题课 admin 新增
    *add_theme({ payload ,callback}, { call, put }) {
       const response = yield call(LoginService.post,'/api/web/system/insertAloneCoursePageC',payload);
       callback(response.data.res,response.data.resMsg);
       yield put({type:'fetch_theme'});
    },
    //主题课 admin 编辑
    *edit_theme({ payload ,callback}, { call, put }) {
      	const response = yield call(LoginService.puts,'/api/web/system/updateAloneCoursePageC',payload);
    	callback(response.data.res,response.data.resMsg);
    	yield put({type:'fetch_theme'});
    },
    //主题课 admin 禁用启用
    *disabled_theme({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.puts,'/api/web/system/updateAloneCoursePageCState', payload);
     	callback(response.data.res,response.data.resMsg);
     	yield put({type:'fetch_theme'});
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
  },
};
